package com.twu.biblioteca;

public abstract class Item {
    public final String name;
    protected boolean checkedOut;

    public Item(String name, boolean checkedOut) {
        this.name = name;
        this.checkedOut = checkedOut;
    }

    public boolean checkOutItem() {
        if (checkedOut) {
            return false;
        }
        checkedOut = true;
        return true;
    }

    public boolean returnItem() {
        if (!checkedOut) {
            return false;
        }
        checkedOut = false;
        return true;
    }

    public String toFormattedString(String format) {
        if (!checkedOut) {
            return String.format(format, fields());
        } else {
            return "";
        }
    }

    protected abstract Object[] fields();
}
